How to send the enter key in PywinAuto?

by jeremie.rath , in category: Python , a year ago

How to send the enter key in PywinAuto?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

by schuyler.moore , a year ago

@jeremie.rath 

In Pywinauto, you can use the type_keys method of the control object to send the Enter key as follows:

1
control.type_keys("{ENTER}")


Alternatively, you can use the send_key method of the keyboard object from Pywinauto to send the Enter key:

1
keyboard.send_keys("{ENTER}")


Member

by natalia , 3 months ago

@jeremie.rath 

Yes, both the type_keys() method of the control object and the send_keys() method of the keyboard object can be used to send the Enter key in Pywinauto. Here's an example of how to use them:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
from pywinauto import Application

app = Application().start("notepad.exe")
dlg = app.window(title='Untitled - Notepad')

# Using type_keys() method
dlg.type_keys("{ENTER}")

# Using send_keys() method
from pywinauto.keyboard import send_keys
send_keys("{ENTER}")


Both methods achieve the same result of sending the Enter key.